import * as TYPES  from '../action-types';
import {Dispatch} from '../../redux';
const actions = {
  increment1() {
    return {type: TYPES.INCREMENT1};
  }

  ,decrement1() {
    return {type: TYPES.DECREMENT1};
  }
  ,asyncIncrement1(){
    return function(dispatch: Dispatch,getState: any){
      setTimeout(() => {
        dispatch({type:TYPES.INCREMENT1})
      }, 1000);
    }
  }
  ,promiseIncrement1(){
    //这种写法只能处理成功
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({type: TYPES.INCREMENT1})
      }, 1000);
    })

    /*return {
      type:TYPES.INCREMENT1
      ,payload: new Promise(function(resolve,reject){
        setTimeout(() => {
          const result = Math.random();
          if (result >= .5) {
            resolve(result);
          } else {
            reject('出错了');
          }
        }, 1000);
      })
    }*/
  }
};

export default actions;
